#include <bits/stdc++.h>
using namespace std;
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a > d || b < c) {
      cout << a + c << endl;
    } else
      cout << max(a, c) << endl;
  }
}
